package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {



    @Autowired
    private CategoryService categoryService;

    //新增
    @PostMapping()
    public R add(@RequestBody Category category){
        return categoryService.add(category);
    }
    //分页查询
    @GetMapping("/page")
    public R findPage(Integer page,Integer pageSize){
        return categoryService.findPage(page,pageSize);
    }
    //根据id删除
    @DeleteMapping()
    public R removeById(Long id){
        return categoryService.removeById(id);
    }
    //修改
    @PutMapping()
    public R updateById(@RequestBody Category category){
        return categoryService.updateById(category);
    }
    //新增菜品时,回显菜品分类
    @GetMapping("/list")
    public R list(Integer type){
        List<Category> categoryList = categoryService.list(type);
        return R.success(categoryList);
    }
}
